define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'crm/bkuser/index',
                    add_url: 'crm/bkuser/add',
                    edit_url: 'crm/bkuser/edit',
                    del_url: 'crm/bkuser/del',
                    multi_url: 'crm/bkuser/multi',
                    table: 'bkuser',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'company', title: __('Company')},
                        {field: 'company_address', title: __('Company_address')},
                        {field: 'company_url', title: __('Company_url'), formatter: Table.api.formatter.url},
                        {field: 'office_tel', title: __('Office_tel')},
                        {field: 'industry', title: __('Industry')},
                        {field: 'companylist', title: __('Companylist'), searchList: {"1":__('Companylist 1'),"2":__('Companylist 2'),"3":__('Companylist 3'),"4":__('Companylist 4'),"5":__('Companylist 5'),"6":__('Companylist 6')}, formatter: Table.api.formatter.normal},
                        {field: 'username', title: __('Username')},
                        {field: 'english_name', title: __('English_name')},
                        {field: 'department', title: __('Department')},
                        {field: 'post', title: __('Post')},
                        {field: 'qq', title: __('Qq')},
                        {field: 'wechat', title: __('Wechat')},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'email', title: __('Email')},
                        {field: 'idcard', title: __('Idcard')},
                        {field: 'education', title: __('Education')},
                        {field: 'salary', title: __('Salary'), operate:'BETWEEN'},
                        {field: 'level', title: __('Level')},
                        {field: 'gender', title: __('Gender'), searchList: {"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.normal},
                        {field: 'birthday', title: __('Birthday'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'station', title: __('Station')},
                        {field: 'admin_ids', title: __('Admin_ids')},
                        {field: 'typelist', title: __('Typelist'), searchList: {"1":__('Typelist 1'),"2":__('Typelist 2')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});